home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / indx18eu.zip / OTHRTEST.PAS < prev    next >
Pascal/Delphi Source File  |  1991-03-15  |  5KB  |  230 lines

  1. PROGRAM OtherTests ;
  2.  
  3.  
  4.  
  5.  
  6. {
  7.  
  8.         Hi,
  9.  
  10.                 Before you run this test ( I hope ) you need to realize that
  11.         the times generated with the MarkTime and ElapsedTime are not very
  12.         acurate.  I've receive times from 5 to 11 hundredths of a second for
  13.         all the below tests ( except the first which is always 0 ).  There's
  14.         no good way to test times on a PC since Interupts will always "steal"
  15.         some of the time during processing.  These times are meant to give you
  16.         a feel for how fast these routines are.  Yes, Move is faster than
  17.         Exchange ( sometimes ), but the move option would require a thrid
  18.         variable of the same size to hold on of the values.  Plus it would
  19.         require two statements to do one thing.  I use it in Qwik sorts, ETC,
  20.         where a lot of swaping is needed and I don't want to be bothered with
  21.         declaring many temp variables.
  22.  
  23. }
  24.  
  25.  
  26.  
  27.  
  28.  
  29. USES
  30.        CRT ,
  31.        DOS ,
  32.        AsmRoutines ;
  33.  
  34.  
  35.  
  36.  
  37. CONST
  38.        MAX_ARR                                   = 60 * 1024 ;
  39.  
  40.  
  41.  
  42. TYPE
  43.        TLargeType                                = ARRAY [ 1 .. MAX_ARR ]
  44.                                                         OF BYTE ;
  45.  
  46.        PLargeType                                = ^TLargeType ;
  47.  
  48.  
  49.  
  50.  
  51. VAR
  52.        h                                         : WORD ;
  53.        m                                         : WORD ;
  54.        s                                         : WORD ;
  55.        hSec                                      : WORD ;
  56.  
  57.  
  58.  
  59.  
  60.  PROCEDURE   MarkTime ;
  61.  
  62.    BEGIN  {  MarkTime  }
  63.  
  64.      GetTime ( h , m , s , hSec ) ;
  65.  
  66.      END ;  {  MarkTime  }
  67.  
  68.  
  69.  
  70.  
  71.  FUNCTION    ElapsedTime                         : LONGINT ;
  72.  
  73.   VAR
  74.        eh                                        : WORD ;
  75.        em                                        : WORD ;
  76.        es                                        : WORD ;
  77.        ehSec                                     : WORD ;
  78.  
  79.    BEGIN  {  ElapsedTime  }
  80.  
  81.      GetTime ( eh , em , es , ehSec ) ;
  82.  
  83.      ElapsedTime := ( ( eh    - h    ) * 60 * 60 * 100 ) +
  84.                     ( ( em    - m    ) * 60 * 100 ) +
  85.                     ( ( es    - s    ) * 100 ) +
  86.                       ( ehSec - hSec ) ;
  87.  
  88.      END ;  {  ElapsedTime  }
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  PROCEDURE   BuildVar ( VAR arr                  : PLargeType ) ;
  95.  
  96.   VAR
  97.        i                                         : WORD ;
  98.  
  99.    BEGIN  {  BuildVar  }
  100.  
  101.      New ( arr ) ;
  102.  
  103.      FOR i := 1 TO MAX_ARR
  104.       DO
  105.          arr^[ i ] := Random ( 256 ) ;     {  0 .. 255  }
  106.  
  107.      END ;  {  BuildVar  }
  108.  
  109.  
  110.  
  111.  
  112. VAR
  113.        arr1                                      : PLargeType ;
  114.        arr2                                      : PLargeType ;
  115.        comp                                      : INTEGER ;
  116.        ch                                        : CHAR ;
  117.        t                                         : LONGINT ;
  118.  
  119.  
  120.  
  121.  
  122. BEGIN
  123.  
  124.   Write ( 'Building two 60K vars...' ) ;
  125.  
  126.   BuildVar ( arr1 ) ;
  127.   BuildVar ( arr2 ) ;
  128.  
  129.   WriteLn ( '...done.' ) ;
  130.   WriteLn ;
  131.   WriteLn ;
  132.  
  133.   Write ( 'Going to compare two 64K vars:  [PRESS ANY KEY]  ' ) ;
  134.   ch := ReadKey ;
  135.   WriteLn ;
  136.  
  137.   Write ( 'arr1 is ' ) ;
  138.  
  139.   MarkTime ;
  140.   comp := Compare ( arr1^ , arr2^ , FALSE , SizeOf ( arr1^ ) ) ;
  141.   t := ElapsedTime ;
  142.  
  143.   CASE comp
  144.    OF
  145.  
  146.       -1  : Write ( 'less than ' ) ;
  147.  
  148.        0  : Write ( 'equal to ' ) ;
  149.  
  150.        1  : Write ( 'greater than ' ) ;
  151.  
  152.    ELSE
  153.  
  154.       WriteLn ;
  155.       WriteLn ( 'ERROR!  Invalid return from Compare!!' ) ;
  156.  
  157.       Halt ( 12 ) ;
  158.  
  159.       END ;  {  CASE  comp  }
  160.  
  161.   WriteLn ( 'arr2.  Took ' , t , ' hundredths of a second.' ) ;
  162.   WriteLn ;
  163.   WriteLn ;
  164.  
  165.  
  166.   Write ( 'Going to exchange two 64K vars:  [PRESS ANY KEY]  ' ) ;
  167.   ch := ReadKey ;
  168.   WriteLn ;
  169.  
  170.   Write ( 'Exchanging to 60K  variables now...' )  ;
  171.  
  172.   MarkTime ;
  173.   Exchange ( arr1^ , arr2^ , SizeOf ( arr1^ ) ) ;
  174.   t := ElapsedTime ;
  175.  
  176.   WriteLn ( 'DONE!  Took ' , t , ' hundredths of a second.' ) ;
  177.   WriteLn ;
  178.  
  179.   Write ( 'Using MOVE from TP would take ' ) ;
  180.  
  181.   MarkTime ;
  182.  
  183.   Move ( arr1^ , arr2^ , SizeOf ( arr1^ ) ) ;
  184.  
  185.   Move ( arr1^ , arr2^ , SizeOf ( arr1^ ) ) ;
  186.  
  187.   t := ElapsedTime ;
  188.  
  189.   WriteLn ( t , ' hundredths of a second plus a third 60K VAR!'  ) ;
  190.   WriteLn ;
  191.   WriteLn ;
  192.  
  193.   Write ( 'Going to compare two 64K vars that are = :  [PRESS ANY KEY]  ' ) ;
  194.   ch := ReadKey ;
  195.   WriteLn ;
  196.  
  197.   WriteLn ( 'Comparing two 60K vars that ARE equal: ' ) ;
  198.  
  199.   Write ( 'arr1 is ' ) ;
  200.  
  201.   MarkTime ;
  202.   comp := Compare ( arr1^ , arr2^ , FALSE , SizeOf ( arr1^ ) ) ;
  203.   t := ElapsedTime ;
  204.  
  205.   CASE comp
  206.    OF
  207.  
  208.       -1  : Write ( 'less than ' ) ;
  209.  
  210.        0  : Write ( 'equal to ' ) ;
  211.  
  212.        1  : Write ( 'greater than ' ) ;
  213.  
  214.    ELSE
  215.  
  216.       WriteLn ;
  217.       WriteLn ( 'ERROR!  Invalid return from Compare!!' ) ;
  218.  
  219.       Halt ( 12 ) ;
  220.  
  221.       END ;  {  CASE  comp  }
  222.  
  223.   WriteLn ( 'arr2.  Took ' , t , ' hundredths of a second.' ) ;
  224.  
  225.   Dispose ( arr1 ) ;
  226.  
  227.   Dispose ( arr2 )  ;
  228.  
  229. END .
  230.